<?php

session_start ();
require_once 'lib/sql.php';
$sql = new Sql ();
$rs = @mysql_query ( "select * from sanpham " );
$count = mysql_num_rows ( $rs );
mysql_free_result ( $rs );
$page1 = 1;
if (isset ( $_GET ['page'] )) {
   $page1 = $_GET ['page'];
}
$count1 = $count - $page1 * 9;
if ($count1 > 9)
   $count1 = 9;

?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>Mobile Shop</title>

<link href="css/style.css" rel="stylesheet" type="text/css" />
<script type="text/javascript">
function MM_jumpMenu(targ,selObj,restore){ //v3.0
  eval(targ+".location='"+selObj.options[selObj.selectedIndex].value+"'");
  if (restore) selObj.selectedIndex=0;
}

function ajax(id) {
	if (window.XMLHttpRequest) { xmlhttp=new XMLHttpRequest(); }
	else { xmlhttp=new ActiveXObject("Microsoft.XMLHTTP"); }

	xmlhttp.open("GET","action/card.php?id="+id,true);
	xmlhttp.send();
	xmlhttp.onreadystatechange=function()
	  { if (xmlhttp.readyState==4 && xmlhttp.status==200) {
	  document.getElementById("cardsp").innerHTML=xmlhttp.responseText;

	 } }
	}
</script>
</head>

<body>
	<div id="container">
      <?php include_once 'includes/header.php';?>
      <?php include_once 'includes/menu.php';?>
		<div id="center">
            <?php include_once 'includes/left.php';?>
			<div id="right">
				<div>
    <?php
   $rs = @mysql_query ( "select * from sanpham LIMIT " . ($page1 * 9 - 9) . ",9" );
   $i = 0;
  
   while ( $row = mysql_fetch_array ( $rs ) ) {
      ?>
      <div id="product">
						<h3>
							<p> <?php echo $row['name']; ?> </p>
						</h3>
						<p>
							<img src="<?php echo $row['image']; ?>" width="180" height="180" />
						</p>
						<p class="price"><?php echo $row['price']; ?>₫</p>
						<p>
							<a href="<?php echo $row['idsp']; ?>" class="readmore">Chi Tiết</a>
							| <input type="button" value="Mua"
								onclick="ajax(<?php echo $row['idsp']; ?>)" />
						</p>
					</div>
      	<?php if($i++%3!=2){?>
      <div id="line"></div>
       <?php
      
      }
   }
   mysql_free_result ( $rs );
   ?>
      </div>
				<div id="pageing">
					<table width="300" border="0" align="center" cellpadding="0"
						cellspacing="0">
						<tr>
							<td height="30">
								<div id="item">
									<a href="index.php?page=1">&lt;&lt;</a>
								</div>
          	<?php for($i=1;$i<=(int)($count/9+1);$i++){?>
            <div id="item<?php if($page1==$i)echo "c"?>">
									<a href="index.php?page=<?php echo $i?>"><?php echo $i?></a>
								</div>
            <?php }?>
           <div id="item">
									<a href="index.php?page=<?php echo (int)(($count/9+1)) ?>">&gt;&gt;</a>
								</div>
							</td>
						</tr>
					</table>
				</div>
			</div>

		</div>
      <?php include_once 'includes/footer.php';?>
	</div>
</body>
</html>
